gallery.js ➔ previewImage   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 1
nop 1
dl 23
loc 23
rs 9.65
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A gallery.js ➔ ... ➔ reader.onload 1 1 1
A gallery.js ➔ ... ➔ reader.onload.constructor 1 1 1
1
/**
2
 * Created by remi on 18/01/15.
3
 */
4 View Code Duplication
(function(){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5
6
7
8
    function previewImage(file) {
9
        var galleryId = "gallery";
10
11
        var gallery = document.getElementById(galleryId);
12
        var imageType = /image.*/;
13
14
        if (!file.type.match(imageType)) {
15
            throw "File Type must be an image";
16
        }
17
18
        var thumb = document.createElement("div");
19
        thumb.classList.add('thumbnail');
20
21
        var img = document.createElement("img");
22
        img.file = file;
23
        thumb.appendChild(img);
24
        gallery.appendChild(thumb);
25
26
        // Using FileReader to display the image content
27
        var reader = new FileReader();
28
        reader.onload = (function(aImg) { return function(e) { aImg.src = e.target.result; }; })(img);
29
        reader.readAsDataURL(file);
30
    }
31
32
    var uploadfiles = document.querySelector('#fileinput');
33
    uploadfiles.addEventListener('change', function () {
34
        var files = this.files;
35
        for(var i=0; i<files.length; i++){
36
            previewImage(this.files[i]);
37
        }
38
39
    }, false);
40
})();